package com.tjetc.test.controller;

import com.tjetc.test.common.PageResult;
import com.tjetc.test.common.Result;
import com.tjetc.test.entity.User;
import com.tjetc.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/9
 */
@RestController
@RequestMapping("/user/")
public class UserController {
    @Autowired
    private UserService userService;


//    @GetMapping("add")
//    public String addUser(User user){
//        userService.addUser(user);
//        return "ok";
//    }

    @GetMapping("add")
    public Result addUser(User user){
        userService.addUser(user);
        return Result.ok();
    }


    @GetMapping("get")
    public Result<User> getUser(@RequestParam("id") int id) {
        User user = userService.getUserById(id);
        return Result.ok("查询成功", user);
    }


    @GetMapping("page")
    public Result<PageResult<List<User>>> getPageUser(@RequestParam("name") String name) {
        PageResult<List<User>> pageResult = userService.getPagerUser(name);
        return Result.ok(pageResult);
    }


}